//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//-------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//-------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================
using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel;
using WCSFContrib.PageFlow.WorkflowFoundation.Properties;
using System.Globalization;

namespace WCSFContrib.PageFlow.WorkflowFoundation.Activities
{
	/// <summary>
	/// Performs design time validation of a PageFlow Activity.
	/// </summary>
	public class PageFlowActivityValidator : ActivityValidator
	{
        /// <summary>
        /// Validate the receive activity
        /// </summary>
        /// <param name="manager">Validation Manager to use</param>
        /// <param name="obj">Activity instance to validate</param>
        /// <returns>Collection of validation errors</returns>
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);

            PageFlow act = (PageFlow)obj;

            if (act.GetValue(PageFlow.NotRunningUrlProperty) != null)
            {
                string notRunningUrl = (string)act.GetValue(PageFlow.NotRunningUrlProperty);
                foreach (Activity activity in act.Activities)
                {
					PageState pageState = activity as PageState;
                    if (pageState != null)
                    {
                        if (pageState.Url != null && pageState.Url.Equals(notRunningUrl, StringComparison.CurrentCultureIgnoreCase))
                        {
							errors.Add(new ValidationError(String.Format(CultureInfo.CurrentCulture, Resources.NotRunningUrlExistsInSomePageState, pageState.Name), 1000));
                        }
                    }
                }
            }
            
            return errors;
        }
	}
}
